{* $Id$ *}
{include_core file="admin/lib/header.html" title="优惠券展示"}
  <div class="page-header border-bottom clearfix">
    <h2 class="left">优惠券管理<span>在这里对优惠券进行管理</span></h2>
    <a href="{AnUrl('coupon/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回优惠券列表</a>
  </div>
  <div class="search-level1 clearfix">
    <form action="coupon/admin/coupon_details" method="get">
      <input type="hidden" name="is_advenced" value="0">
      <input type="hidden" name="status" value="{$status}">
      <input type="hidden" name="id" value="{$id}">
      <input {if $is_advenced == 1}style="display:none;"{/if} type="text" class="left" name="search_filter[coupon_code]" value="{$search_filter.coupon_code}">
      <button {if $is_advenced == 1}style="display:none;"{/if} type="submit" class="btn btn-success btn-sm left">搜索</button>
      <a href="javascript:void(0);" class="close js_advanced {if $is_advenced == 1}js_isOpen open{/if}">高级搜索<em></em></a>
    </form>
  </div>
  <div class="search-form js_advancedForm" {if $is_advenced == 0}style="display:none;"{/if}>
    <form action="coupon/admin/coupon_details" method="get" class="js_couponSearchForm">
      <input type="hidden" name="is_advenced" value="1">
      <input type="hidden" name="status" value="{$status}">
      <input type="hidden" name="id" value="{$id}">
      <p>
        <label for="" class="search-f-label">优惠券编码：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[coupon_code]" value="{$search_filter.coupon_code}">
      </p>
      <p>
        <label for="" class="search-f-label">使用用户：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[user_name]" value="{$search_filter.user_name}">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>
  <!--start:列表-->
  <table class="list-table">
    <caption>按状态：
      <a href='{AnUrl("coupon/admin/coupon_details?status=1&&id=$id")}' {if $status == 1} class="label label-primary" {else} class="label label-default" {/if}>未领取</a>
      <a href='{AnUrl("coupon/admin/coupon_details?status=2&&id=$id")}' {if $status == 2} class="label label-primary" {else} class="label label-default" {/if}>已领取</a>
      <a href='{AnUrl("coupon/admin/coupon_details?status=3&&id=$id")}' {if $status == 3} class="label label-primary" {else} class="label label-default" {/if}>已使用</a>
    </caption>
    <caption>导出表格(一页2000个)：
    {$page_num = ceil($coupon_relation_count/coupon_config::$excel_num_page)}
    {foreach range(1,$page_num) as $v}
      <a href='{AnUrl("coupon/admin/download_list?id=$id&&page_no=$v")}' class="label label-primary">第{$v}页</a>
    {/foreach}
    
    </caption>
    <thead><tr>
      <th style="min-width:120px;">优惠券编码</th>
      <th style="min-width:150px;">有效期</th>
      {if $coupon_info.is_all_user}
      <th>使用次数</th>
      {else}
      <th>领取人</th>
      <th>使用时间</th>
      <th style="width:60px;">状态</th>
      {/if}
    </tr></thead>
    <tbody>
      {foreach $coupon_details_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if} data-id="{$v.id}">
          <td>{$v.coupon_code}</td>
          <td>{date('Y-m-d',strtotime($coupon_info.start_time))}至{date('Y-m-d',strtotime($coupon_info.end_time))}</td>
          {if $coupon_info.is_all_user}
          <td>{$v.use_num}</td>
          {else}
          <td>
            {$user_info = _uri('user', $v.user_id)}{if $user_info.user_name}{$user_info.user_name}{else}{$user_info.mobile}{/if}
          </td>
          <td>{$v.use_time}</td>
          <td>
            {if $coupon_info.is_valid}
            {if $v.status == coupon_config::COUPON_AVAILABLE}
            <p class="btn btn-xs btn-default">{coupon_config::$coupon_status[coupon_config::COUPON_AVAILABLE]}</p>
            {elseif $v.status == coupon_config::COUPON_RECEIVE}
            <p class="btn btn-xs btn-primary">{coupon_config::$coupon_status[coupon_config::COUPON_RECEIVE]}</p>
            {elseif $v.status == coupon_config::COUPON_USE}
            <p class="btn btn-xs btn-success">{coupon_config::$coupon_status[coupon_config::COUPON_USE]}</p>
            {/if}
            {else}
            <p class="btn btn-xs btn-danger">{coupon_config::$coupon_status[coupon_config::COUPON_OVERDUE]}</p>
            {/if}
          </td>
          {/if}
        </tr>
      {foreachelse}
          <tr><td class="txtleft" colspan="6">暂无数据</td></tr>
      {/foreach}
    </tbody>
  </table>
  {include_core file="admin/lib/pager.html"}
<!--end:列表-->
{load_js file='zclip/jquery.zclip.min.js'}
{load_js file='zclip/ZeroClipboard.js'}
<script>
$(function(){
  // 高级搜索
  $('.js_advanced').click(function(e){
    e.preventDefault();
    var thisObj = $(this);
    var outBox  = thisObj.closest('form');
    if (thisObj.hasClass('js_isOpen')) {
      thisObj.removeClass('js_isOpen open');
      outBox.find('input').show();
      outBox.find('button').show();
      $('.js_advancedForm').hide();
    } else {
      thisObj.addClass('js_isOpen open');
      outBox.find('input').hide();
      outBox.find('button').hide();
      $('.js_advancedForm').show();
    }
  });
  
  // 高级搜索时间验证
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var thisObj   = $(this);
    var startDate = $.trim($('#startDate').val());
    var stopDate  = $.trim($('#stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return;
    }
    thisObj.closest('form').submit();
  });
});
</script>
{include_core file="admin/lib/footer.html"}